<?php
namespace BP\GPM\AD;
class Glo {
	protected static $LOGON32_LOGON_INTERACTIVE;	// int
	protected static $LOGON32_PROVIDER_DEFAULT;	// int
	protected static $impersonationContext;	// WindowsImpersonationContext
	public static function __staticinit() { // static class members
		self::$LOGON32_LOGON_INTERACTIVE = 2;
		self::$LOGON32_PROVIDER_DEFAULT = 0;
		self::$impersonationContext = NULL;
	}
	public static function getADBasePath () 
	{
		return $Sys->SystemConfig->AppSettings["ADBasePath"];
	}
	public static function getADUser () 
	{
		return $Sys->SystemConfig->AppSettings["ADUser"];
	}
	public static function getADPassword () 
	{
		return $Sys->SystemConfig->AppSettings["ADPassword"];
	}
	public static function getADPath () 
	{
		return $Sys->SystemConfig->AppSettings["ADPath"];
	}
	public static function getDirectoryEntryBasePath () 
	{
		$domain = new DirectoryEntry();
		$domain->Path = Glo::getADBasePath();
		$domain->Username = Glo::getADUser();
		$domain->Password = Glo::getADPassword();
		return $domain;
	}
	public static function getDirectoryEntryAppRoot () 
	{
		$search = new DirectorySearcher(Glo::getDirectoryEntryBasePath());
		$search->Filter = (("(OU=" . Glo::getADPath()) . ")");
		$search->SearchScope = $SearchScope->Subtree;
		$result = $search->FindOne();
		if (($result == NULL))
		{
			throw new \RuntimeException(("err@您配置的:ADAppRoot无效,正确的配置方法比�?:chichengsoft 没有找到该节�?." . Glo::getADPath()));
		}
		$de = $result->GetDirectoryEntry();
		$search->Dispose();
		return $de;
	}
	public static function GetPropertyValue ($de, $propertyName) // [DirectoryEntry de, String propertyName]
	{
		if ($de->Properties->Contains($propertyName))
		{
			return $de->Properties[$propertyName][0];
		}
		else
		{
			return "";
		}
	}
	abstract static function LogonUser11 ($lpszUsername, $lpszDomain, $lpszPassword, $dwLogonType, $dwLogonProvider, $phToken); // [String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, tangible.RefObject<IntPtr> phToken]
	abstract static function LogonUser ($lpszUserName, $lpszDomain, $lpszPassword, $dwLogonType, $dwLogonProvider, $phToken); // [String lpszUserName, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, tangible.RefObject<IntPtr> phToken]
	abstract static function DuplicateToken ($hToken, $impersonationLevel, $hNewToken); // [IntPtr hToken, int impersonationLevel, tangible.RefObject<IntPtr> hNewToken]
	public static function CheckLogin ($domain, $userNo, $pass) // [String domain, String userNo, String pass]
	{
		$entry = new DirectoryEntry($BP->GPM->AD->Glo->getADBasePath(), $userNo, $pass);
		$search = new DirectorySearcher($entry);
		$search->Filter = (("(SAMAccountName=" . $userNo) . ")");
		$result = $search->FindOne();
		if ((NULL == $result))
		{
			return  FALSE ;
		}
		return  TRUE ;
	}
}
Glo::__staticinit(); // initialize static vars for this class on load
?>
